<template>
	<view>
		<form>
			<view class="cu-form-group">
				<view class="title">当前密码</view>
				<input name="input" type="password" v-model="password"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">新密码</view>
				<input name="input" type="password" v-model="new_password"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">再次输入新密码</view>
				<input name="input" type="password" v-model="new_confirm_password"></input>
			</view>
			<view class="padding flex flex-direction">
				<button class="cu-btn bg-grey lg" @click="savePassword">保存</button>
			</view>
		</form>
	</view>
</template>

<script>
	import { editPassword } from '../../api/account.js';
	export default {
		data() {
			return {
				password:'',
				new_password:'',
				new_confirm_password:''
			};
		},
		methods: {
			savePassword() {
				if (this.password.trim() === '') {
					uni.showToast({ title: '请填写密码', icon: 'none' });
					return
				}
				if (this.new_password.trim() === '') {
					uni.showToast({ title: '请填写新密码', icon: 'none' });
					return
				}
				if (this.new_confirm_password.trim() === '') {
					uni.showToast({ title: '请填写确认密码', icon: 'none' });
					return
				}
				var data = {
					password: this.password,
					new_password: this.new_password,
					confirm_new_password: this.new_confirm_password
				}
				editPassword(data).then(res => {
					if (res.ok != undefined) {
						uni.showToast({ title: '保存成功', icon: 'none' });
					} else {
						uni.showToast({ title: res.msg, icon: 'none' });
					}
					
				}).catch(err => {
					uni.showToast({ title: '保存失败', icon: 'none' });
				});
			}
		}
	}
</script>

<style>

</style>
